package com.bdqn.t382.entity;

import com.bdqn.t382.dao.Ink;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


import java.util.Random;
public class Printer {
    private static final Logger logger = LoggerFactory.getLogger(Printer.class);
    private Ink ink;
    private Paper paper;


    public Printer(Ink ink, Paper paper) {
        this.ink = ink;
        this.paper = paper;
        logger.info("创建打印机，使用 {} 墨盒，纸张规格：{}", ink.getColor(), paper.getSize());
    }

    public void print(String content) {
        Random random = new Random();
        int randomNum = random.nextInt(10);

        if (randomNum < 5) {
            logger.info("使用 {} 墨盒，在 {} 纸张上打印内容：{}", ink.getColor(), paper.getSize(), content);
        } else if (randomNum >= 5 && randomNum <= 7) {
            throw new PaperJamException("打印机卡纸，请检查纸张。");
        } else {
            throw new NoInkException("墨盒无墨，请更换墨盒。");
        }
    }
    // 卡纸异常类
    class PaperJamException extends RuntimeException {
        public PaperJamException(String message) {
            super(message);
        }
    }

    // 墨盒无墨异常类
    class NoInkException extends RuntimeException {
        public NoInkException(String message) {
            super(message);
        }
    }
}
